package com.my.mall.client.wechat.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.my.mall.client.wechat.dao.WXClientDao;
import com.my.mall.client.wechat.dto.UserDetailsClientDTO;
import com.my.mall.client.wechat.dto.UserInfoClientDTO;
import com.my.mall.client.wechat.vo.GoodsInfoVo;
import com.my.mall.client.wechat.vo.OrderInfoClientVo;
import com.my.mall.client.wechat.vo.ShippingAddressClientVo;
import com.my.mall.client.wechat.vo.UserDetailsClientVo;
import com.my.mall.client.wechat.vo.UserInfoClientVo;

@Service
public class WXClientService {

	@Autowired
	WXClientDao wxClientDao;

	/**
	 * 用户信息表的数据添加
	 * 
	 * @param wxClientDTO
	 * @return
	 */
	public int saveUserInfo(UserInfoClientDTO wxClientDTO) {
		return wxClientDao.saveUserInfo(wxClientDTO);
	}

	/**
	 * 用户信息表的数据更新
	 * 
	 * @param wxClientDTO
	 * @return
	 */
	public int updateUserInfo(UserInfoClientDTO wxClientDTO) {
		return wxClientDao.updateUserInfo(wxClientDTO);
	}

	/**
	 * 根据openid查询用户信息表的数据
	 * 
	 * @param openId
	 * @return
	 */
	public UserInfoClientVo getUserByOpenId(String openId) {
		return wxClientDao.getUserByOpenId(openId);
	}

	/**
	 * 用户信息表的添加
	 * 
	 * @param userDetailsClientDTO
	 * @return
	 */
	public int saveUserDetails(UserDetailsClientDTO userDetailsClientDTO) {
		return wxClientDao.saveUserDetails(userDetailsClientDTO);
	}

	/**
	 * 用户信息表的更新
	 * 
	 * @param userDetailsClientDTO
	 * @return
	 */
	public int updateUserDetails(UserDetailsClientDTO userDetailsClientDTO) {
		return wxClientDao.updateUserDetails(userDetailsClientDTO);
	}

	/**
	 * 根据openid查询用户信息详情表的数据
	 * 
	 * @param openId
	 * @return
	 */
	public UserDetailsClientVo getUserDetailsByOpenId(String openid) {
		return wxClientDao.getUserDetailsByOpenId(openid);
	}

	/**
	 * 根据userId查询 收货地址管理表 的所有数据
	 * 
	 * @param shippingAddressClientVo
	 * @return
	 */
	public List<ShippingAddressClientVo> selectShippingAddressList(int userId) {
		return wxClientDao.selectShippingAddressList(userId);
	}

	/**
	 * 根据userId查询 订单信息主表 的所有数据
	 * 
	 * @param orderInfoClientVo
	 * @return
	 */
	public List<OrderInfoClientVo> selectOrderInfoList(int userId) {
		List<OrderInfoClientVo> list = wxClientDao.selectOrderInfoList(userId);
		for (OrderInfoClientVo orderInfo : list) {
			GoodsInfoVo goodsInfo = wxClientDao.getGoodsInfoByOrderId(orderInfo.getId());
			if (goodsInfo != null) {
				orderInfo.setGoodsImgPath(goodsInfo.getImgUrl());
				orderInfo.setGoodsCount(goodsInfo.getGoodsCount());
			}
		}
		return list;
	}

}
